﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;

namespace Admin.WorkFlow.WorkFlowManage
{
    public partial class Modify : Page
    {       
        protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
                BindRole();
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int PmFlowId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(PmFlowId);
				}
			}
		}


        private void BindRole()
        {
            ChinaSoft.BLL.BLL_tb_MidSoft_Roles bllRoles = new ChinaSoft.BLL.BLL_tb_MidSoft_Roles();
            ChinaSoft.Model.Model_tb_MidSoft_Roles modelRoles = new ChinaSoft.Model.Model_tb_MidSoft_Roles();
            System.Data.DataSet ds = bllRoles.GetAllList();
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                ddlRole.DataSource = ds;
                ddlRole.DataTextField = "RoleName";
                ddlRole.DataValueField = "RolesId";
                ddlRole.DataBind();
            }
        }
	private void ShowInfo(int PmFlowId)
	{
		ChinaSoft.BLL.BLL_tb_MidSoft_PmFlow bll=new ChinaSoft.BLL.BLL_tb_MidSoft_PmFlow();
		ChinaSoft.Model.Model_tb_MidSoft_PmFlow model=bll.GetModel(PmFlowId);
		this.txtFlowName.Text=model.FlowName;
		this.txtNewForm.Text=model.NewForm;
		this.txtEditForm.Text=model.EditForm;
		this.txtReadonlyForm.Text=model.ReadonlyForm;
        this.ddlRole.SelectedItem.Text = model.StartRole;
	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtFlowName.Text.Trim().Length==0)
			{
				strErr+="流程名称不能为空！\\n";	
			}
			if(this.txtNewForm.Text.Trim().Length==0)
			{
				strErr+="新建表单不能为空！\\n";	
			}
			if(this.txtEditForm.Text.Trim().Length==0)
			{
				strErr+="编辑表单不能为空！\\n";	
			}
			if(this.txtReadonlyForm.Text.Trim().Length==0)
			{
				strErr+="只读表单不能为空！\\n";	
			}
			if(this.ddlRole.SelectedItem.Value=="")
			{
				strErr+="流程启动角色不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
            int PmFlowId = ChinaSoft.Common.Input.SetInt(Request.Params["id"]);
			string FlowName=this.txtFlowName.Text;
			string NewForm=this.txtNewForm.Text;
			string EditForm=this.txtEditForm.Text;
			string ReadonlyForm=this.txtReadonlyForm.Text;
			string StartRole=this.ddlRole.SelectedItem.Text;

            ChinaSoft.BLL.BLL_tb_MidSoft_PmFlow bll = new ChinaSoft.BLL.BLL_tb_MidSoft_PmFlow();
			ChinaSoft.Model.Model_tb_MidSoft_PmFlow model=bll.GetModel(PmFlowId);
			model.FlowName=FlowName;
			model.NewForm=NewForm;
			model.EditForm=EditForm;
			model.ReadonlyForm=ReadonlyForm;
			model.StartRole=StartRole;
			bll.Update(model);
            Response.Write("<script>alert('成功！');top.window.parent.frames.item('workspace').location.reload();window.parent.$('#DivSysiframe').dialog(\"close\");</script>");
		}
    }
}
